﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FinalSettlementModel
{
    public class TableNguonVon_PheDuyet : Helper
    {
        // Hàm lấy danh sách nguồn vốn theo Id phê duyệt
        public IQueryable<TblNguonVon_PheDuyet> ListCapital_ApproveData(int IdApprove)
        {
            var capitalApprove = from capital in nc.TblNguonVon_PheDuyets
                                 where capital.PheDuyetId == IdApprove
                                 select capital;

            return capitalApprove;
        }
        
        // Hàm tạo mới dữ liệu nguồn vốn theo hồ sơ phê duyệt
        public void insertCapital_Approve(int IdApprove, int IdCapital)
        {
            TblNguonVon_PheDuyet capitalApp = new TblNguonVon_PheDuyet();
            capitalApp.PheDuyetId = IdApprove;
            capitalApp.NguonVonId = IdCapital;
            nc.TblNguonVon_PheDuyets.InsertOnSubmit(capitalApp);
            nc.SubmitChanges();
        }

        // Hàm xóa dữ liệu nguồn vốn theo hồ sơ phê duyệt
        public void deleteCapital_Approve(int idPheDuyet)
        {
            var delete = nc.TblNguonVon_PheDuyets.Where(s => s.PheDuyetId == idPheDuyet);
            nc.TblNguonVon_PheDuyets.DeleteAllOnSubmit(delete);
            nc.SubmitChanges();
        } 
    }
}
